use xiaohao_ar::binary_tree_ar::*;

// 1.
#[test]
fn max_depth_test() {
    let v1 = vec![3, 9, 20, 0, 0, 15, 7];
    assert_eq!(3, max_depth(&v1, 0));
}
// 1.2
#[test]
fn traversal_test() {
    let v1 = vec![3, 9, 20, 0, 0, 15, 7];
    assert_eq!(3, traversal(&v1));
}
// 1.3
#[test]
fn bfs_test() {
    let v1 = vec![3, 9, 20, 0, 0, 15, 7];
    let mut index = vec![vec![0]];
    assert_eq!(3, bfs(&v1, &mut index).len());
}
// 1.4
#[test]
fn level_order_test() {
    let v1 = vec![3, 9, 20, 0, 0, 15, 7];
    assert_eq!(3, level_order(&v1));
}

// 2. 二叉搜索树
#[test]
fn is_valid_bst_test() {
    let v1 = vec![17, 5, 35, 2, 16, 29, 38, 0, 0, 0, 0, 19, 33];
    assert_eq!(true, is_valid_bst(&v1));
    let v2 = vec![5, 1, 4, 0, 0, 3, 6];
    assert_eq!(false, is_valid_bst(&v2));
    let v3 = vec![5, 1, 9, 0, 0, 3, 11];
    assert_eq!(false, is_valid_bst(&v3));
}

// 3. binary search tree (search)
#[test]
fn search_bst_recursive_test() {
    let v1 = vec![5, 3, 9, 0, 0, 7, 18];
    assert_eq!(Some(5), search_bst_recursive(&v1, 0, 7));
    let v2 = vec![5, 3, 9, 0, 0, 7, 18];
    assert_eq!(Some(5), search_bst_iteration(&v2, 7));
}

// 4.
#[test]
fn delete_node_backward_test() {
    let mut v1 = vec![5, 3, 7, 2, 4, 6, 9];
    assert_eq!(Some(5), delete_node_backward(&mut v1, 0, 5));
}
// 4.1
#[test]
fn delete_node_forward_test() {
    let mut v1 = vec![5, 3, 7, 2, 4, 6, 9];
    assert_eq!(Some(4), delete_node_forward(&mut v1, 0, 5));
}

// 5.
#[test]
fn is_balanced_test() {
    let v1 = vec![3, 9, 20, 0, 0, 15, 7];
    assert_eq!(true, is_balanced(&v1, 0));
    let v2 = vec![1, 2, 2, 3, 3, 0, 0, 4, 4];
    assert_eq!(false, is_balanced(&v2, 0));
}

// 6.
#[test]
fn count_nodes_test() {
    let v1 = vec![1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 5];
    assert_eq!(10, count_nodes(&v1, 0));
}
// 6.1
#[test]
fn count_nodes_typical_test() {
    let v2 = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    assert_eq!(10, count_nodes_typical(&v2, 0));
}
